package com.uwlaser.modules.system.rest;

import com.uwlaser.annotation.Log;
import com.uwlaser.modules.system.domain.SysExternalWebserviceLog;
import com.uwlaser.modules.system.service.SysExternalWebserviceLogService;
import com.uwlaser.modules.system.service.dto.SysExternalWebserviceLogDto;
import com.uwlaser.modules.system.service.dto.SysExternalWebserviceLogQueryParam;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.util.Set;

/**
* @author QZK
* @date 2022-12-07
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "WebService请求日志管理")
@RequestMapping("/api/sysExternalWebserviceLog")
public class SysExternalWebserviceLogController {

    private final SysExternalWebserviceLogService sysExternalWebserviceLogService;

    @GetMapping
    @Log("查询WebService请求日志")
    @ApiOperation("查询WebService请求日志")
    @PreAuthorize("@el.check('sysExternalWebserviceLog:list')")
    public ResponseEntity query(SysExternalWebserviceLogQueryParam query, Pageable pageable){
        return new ResponseEntity<>(sysExternalWebserviceLogService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增WebService请求日志")
    @ApiOperation("新增WebService请求日志")
    @PreAuthorize("@el.check('sysExternalWebserviceLog:add')")
    public ResponseEntity create(@Validated @RequestBody SysExternalWebserviceLogDto resources){
        return new ResponseEntity<>(sysExternalWebserviceLogService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改WebService请求日志")
    @ApiOperation("修改WebService请求日志")
    @PreAuthorize("@el.check('sysExternalWebserviceLog:edit')")
    public ResponseEntity update(@Validated @RequestBody SysExternalWebserviceLogDto resources){
        sysExternalWebserviceLogService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除WebService请求日志")
    @ApiOperation("删除WebService请求日志")
    @PreAuthorize("@el.check('sysExternalWebserviceLog:del')")
    public ResponseEntity delete(@RequestBody Set<Integer> ids) {
        sysExternalWebserviceLogService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @PostMapping("/reuploadOne")
    @Log("WebService请求单条重传")
    @ApiOperation("WebService请求单条重传")
    @PreAuthorize("@el.check('sysExternalWebServiceLog:edit')")
    public ResponseEntity reuploadOne(@RequestBody SysExternalWebserviceLog resources) throws Exception {
        sysExternalWebserviceLogService.reuploadOne(resources);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @GetMapping("/reuploadAll")
    @Log("WebService请求一键重传")
    @ApiOperation("WebService请求一键重传")
    @PreAuthorize("@el.check('sysExternalWebServiceLog:edit')")
    public ResponseEntity reuploadAll(){
        sysExternalWebserviceLogService.reuploadAll();
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出WebService请求日志")
    @ApiOperation("导出WebService请求日志")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('sysExternalWebserviceLog:list')")
    public void download(HttpServletResponse response, SysExternalWebserviceLogQueryParam query) throws IOException {
        sysExternalWebserviceLogService.download(sysExternalWebserviceLogService.queryAll(query), response);
    }*/

}
